import { createStore } from 'vuex'
import login from './login/login'
import system from './main/system/system'
import { getPageListData } from '../service/mian/system/system'
import dashboardModule from './main/analysis/dashboard'
const store = createStore({
  state: {
    // 面包屑
    navParent: '',
    navChild: '',
    // 全部部门
    entireDepartment: [],
    // 全部角色
    entireRole: [],
    //
    entireMenu: []
  },
  mutations: {
    childClick(state, paload) {
      state.navChild = paload
    },
    prantClick(state, paload) {
      state.navParent = paload
    },
    changeDepartmentData(state, list) {
      state.entireDepartment = list
    },
    changeRoleData(state, list) {
      state.entireRole = list
    },
    changeMenuData(state, list) {
      state.entireMenu = list
    }
  },
  actions: {
    async getInitialDataAction({ commit }) {
      // 请求部门数据
      const departmentResult = await getPageListData('/department/list', {
        offset: 0,
        size: 100
      })
      const departmentList = departmentResult.data.list
      // 请求角色数据
      const roletResult = await getPageListData('/role/list', {
        offset: 0,
        size: 100
      })
      const roleList = roletResult.data.list
      // 请求部门数据
      const menuResult = await getPageListData('/menu/list', {})
      const menuList = menuResult.data.list

      // 保存数据
      commit('changeDepartmentData', departmentList)
      commit('changeRoleData', roleList)
      commit('changeMenuData', menuList)
    }
  },
  modules: {
    system,
    login,
    dashboardModule
  }
})
export function setupStore() {
  store.dispatch('getInitialDataAction')
}
export default store
